package hibernate;

/**
 *
 * @author Igor Kovb
 */
public class User extends DBEntity {

    private String login;
    private String password;
    private String firstName;
    private String lastName;
    private String email;
    private UserRole role;

    User() {
    }

    private User(String login, String password, String firstName, String lastName,
            String email, UserRole role) {
        this.login = login;
        this.password = password;
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.role = role;
    }
    private static User GUEST = new User("Guest", "нискажу", "Гостюшка", "Гостевич", "Гость тчк Маил сабака ру", UserRole.GET_GUEST_ROLE());

    /**
     * @author SBelonozko, Igor Kovb
     * 
     * Возвращает Особого пользователя - Гостя. Это незарегестрированный пользователь.
     * @return объект класса пользователь
     * <b>NOT NULLABE</b>
     */
    public static User GET_GUEST_USER() {
        User res = new User();
        res.setId(GUEST.getId());
        res.setLogin(GUEST.getLogin());
        res.setPassword(GUEST.getPassword());
        res.setEmail(GUEST.getEmail());
        res.setFirstName(GUEST.getFirstName());
        res.setLastName(GUEST.getLastName());
        res.setRole(GUEST.getRole());
        return res;
    }

    /**
     * O_0 code
     * @param r - the user class object to compare
     * @return true, if classes describe one row in users table
     */
    public boolean equals(User r) {
        boolean res = false;
        if (this.getId() == r.getId()
                && this.getEmail().equals(r.getEmail())
                && this.getFirstName().equals(r.getFirstName())
                && this.getLastName().equals(r.getFirstName())
                && this.getLogin().equals(r.getLogin())
                && this.getPassword().equals(r.getPassword())
                && this.getRole().equals(r.getRole())) {

            res = true;
        }
        return res;
    }

    @Override
    public boolean equals(Object o) {
        boolean res = false;
        if (o instanceof User) {
            User p = (User) o;
            res = this.equals(p);
        }
        return res;
    }

    /**
     * @return the login
     */
    public String getLogin() {
        return login;
    }

    /**
     * @param login the login to set
     */
    public void setLogin(String login) {
        this.login = login;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the firstName
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * @param firstName the firstName to set
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * @return the lastName
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * @param lastName the lastName to set
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * @return the role
     */
    public UserRole getRole() {
        return role;
    }

    /**
     * @param role the role to set
     */
    public void setRole(UserRole u) {
        this.role = u;
    }

    @Override
    public String toString() {
        return "id " + getId() + " login: " + login + " password: " + password
                + " name: " + firstName + " " + lastName + " email" + getEmail()
                + " role: " + role.getRoleName();
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }
}
